///////////////////////////////////////////////////////////////////////////
//
//  @ File      :   res_manager.h
//  @ Author    :   zhoukaifeng<zhoukaifeng@kingsoft.com>
//  @ DateTime  :   2014-10-24 15:32:28 
//  @ Brief     :
//
///////////////////////////////////////////////////////////////////////////

#ifndef __RES_MANAGER_2014_10_24_15_32_28__
#define __RES_MANAGER_2014_10_24_15_32_28__

#include "stdafx.h"
#include <GdiPlus.h>
#pragma comment(lib, "gdiplus.lib")


#define RES_XML_TYPE  _T("xml")
#define RES_BMP_TYPE  _T("bmp")
#define RES_PNG_TYPE  _T("png")
#define RES_JPG_TYPE  _T("jpg")

class GdiPlusInit
{
public:
    GdiPlusInit()
    {
        Gdiplus::GdiplusStartup(&m_diplusToken, &m_diplusStartupInput, NULL);
    }

    ~GdiPlusInit()
    {
        Gdiplus::GdiplusShutdown(m_diplusToken);
    }

    ULONG_PTR                       m_diplusToken;
    Gdiplus::GdiplusStartupInput    m_diplusStartupInput;
};

class ResManager
{
    DECLARE_SINGLETON(ResManager)
public:
    void SetResourcePath(LPCTSTR lpszResPath);
    void SetResourceModule(HINSTANCE hResMoudle);

    BOOL LoadBmpFromResourceID(const CString& strResID, HBITMAP &hBitmap);
    BOOL LoadImgFromResourceID(const CString& strResID, LPCTSTR lpszResType, Gdiplus::Image* &pImg);
    BOOL LoadResource(const CString& strResID, CStringA &strBuffRet, LPCTSTR lpszResType = RES_XML_TYPE);

protected:
    BOOL _LoadResourceFromModule(HINSTANCE hModule, UINT uResID, CStringA &strRet, LPCTSTR lpszResType);
    BOOL _LoadResourceFromResourcePath(const CString& strResID, CStringA &strBuffRet, LPCTSTR lpszResType);

private:
    BOOL GetResourceIntID(const CString& strResID, UINT& uResID);

private:
    CString         m_strResourcePath;
    HINSTANCE       m_hResourceModule;
};

#endif